package com.itheima.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.itheima.pojo.CheckGroup;
import com.itheima.pojo.CheckItem;
import org.apache.ibatis.annotations.*;
import org.springframework.web.bind.annotation.RequestParam;

import java.util.List;

/**
 * @author ：yuanjian
 * @date ：Created in 2020/11/11 14:52
 * @description：
 */
public interface CheckGroupMapper extends BaseMapper<CheckGroup> {
    @Insert("insert into `t_checkgroup_checkitem` values(#{checkitemId},#{groupId})")
    void addCheckGroupAndCheckItemIds(@Param("checkitemId") Long checkitemId, @Param("groupId") Long groupId);

    @Insert("insert into t_check_group values(null,#{code},#{name},#{helpcode},#{sex},#{remark},#{attention})")
    @SelectKey(keyProperty = "id",keyColumn = "id",statement = "select last_insert_id()",before = false, resultType = Long.class)
    void add(CheckGroup checkGroup);

    @Select("select checkitem_id from `t_checkgroup_checkitem`  where checkgroup_id=#{checkGroupId}")
    List<Long> findCheckItemByCheckGroupId(Long checkGroupId);

    @Delete("delete from `t_checkgroup_checkitem` where checkgroup_id=#{checkGroupId}")
    void deleteCheckGroupAndCheckItemIds(Long groupId);

    @Select("select tc.* \n" +
            "from `t_checkgroup_checkitem` tcgc \n" +
            "left join t_check_item tc on tc.id = tcgc.checkitem_id \n" +
            "where tc.is_delete=0 and tcgc.checkgroup_id=#{checkGroupId}")
    List<CheckItem> findCheckItemsByCheckGroupId(Long checkGroupId);

    /*@Select("SELECT tc.NAME " +
            "FROM  t_checkitem tc,t_checkgroup_checkitem tcgc " +
            "WHERE tc.id = tcgc.CHECKITEM_ID and tc.is_delete=0 AND tcgc.CHECKGROUP_ID =#{gid}")
    List<CheckItem> findCheckItemsByGroupId(@Param("gid") Integer gid);*/
}
